
using System;
using System.Collections.Generic;
using BTKERP.Model;
using BTKERP.DAL.DataAccess;
using System;

namespace BTKERP.DAL
{
	#region GRNMasterDAL
	public class GRNMasterDAL : DBContext
	{
		public List<GRNMaster> GetAll()
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_GRNMastersSelectAll");
            return GetEntityList<GRNMaster>(cmd);
        }

        public GRNMaster GetById(Guid id)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_GRNMasterSelect");
            cmd.AddParameter("@Id", id);
            return GetSingleEntity<GRNMaster>(cmd);
        }

		public List<GRNMaster> GetByDynamicSQL(string sqlCondition)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_GRNMasterSelectDynamic");
            cmd.AddParameter("@SQL", sqlCondition);
            return GetEntityList<GRNMaster>(cmd);
        }

        public GRNMaster Add(string paramGRNCode, DateTime paramGRNDate, Guid paramSupplierId, Guid paramReceivedWarehouseId, string paramRemark,
                                   int paramStatus, string paramCreatedBy)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_GRNMasterInsert");
            cmd.AddParameter("@GRNCode", paramGRNCode);
            cmd.AddParameter("@GRNDate", paramGRNDate);
            cmd.AddParameter("@SupplierId", paramSupplierId);
            cmd.AddParameter("@ReceivedWarehouseId", paramReceivedWarehouseId);
            cmd.AddParameter("@Remark", paramRemark);
            cmd.AddParameter("@Status", paramStatus);
            cmd.AddParameter("@CreatedBy", paramCreatedBy);
            return GetSingleEntity<GRNMaster>(cmd);
        }

        public bool DeleteById(Guid id)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_GRNMasterDelete");
            cmd.AddParameter("@Id", id);
            return ExecuteCommand(cmd);
        }

        public GRNMaster UpdateById(Guid paramId, string paramGRNCode, DateTime paramGRNDate, Guid paramSupplierId, Guid paramReceivedWarehouseId, string paramRemark,
                                    decimal paramReceivedQuantity, decimal paramReceivedValue, int paramStatus, bool paramIsConsignment, decimal paramConsignmentComission,
                                    string paramUpdatedBy)
        {
            ExSQLCommand cmd = new ExSQLCommand("usp_GRNMasterUpdate");
			cmd.AddParameter("@Id", paramId);
			cmd.AddParameter("@GRNCode", paramGRNCode);
			cmd.AddParameter("@GRNDate", paramGRNDate);
			cmd.AddParameter("@SupplierId", paramSupplierId);
			cmd.AddParameter("@ReceivedWarehouseId", paramReceivedWarehouseId);
			cmd.AddParameter("@Remark", paramRemark);
			cmd.AddParameter("@ReceivedQuantity", paramReceivedQuantity);
			cmd.AddParameter("@ReceivedValue", paramReceivedValue);
			cmd.AddParameter("@Status", paramStatus);
			cmd.AddParameter("@IsConsignment", paramIsConsignment);
			cmd.AddParameter("@ConsignmentComission", paramConsignmentComission);
            cmd.AddParameter("@UpdatedBy", paramUpdatedBy);
            return GetSingleEntity<GRNMaster>(cmd);
        }
		
	}
	#endregion
}
